# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname="${MINGW_PACKAGE_PREFIX}-python2-backports.os"
pkgver=0.1.1
pkgrel=1
pkgdesc="Backport of new features in Python's os module"
arch=('any')
url="https://github.com/pjdelport/backports.os"
license=('PSF')
depends=("${MINGW_PACKAGE_PREFIX}-python2-backports" 
         "${MINGW_PACKAGE_PREFIX}-python2-future")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools-scm")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest-runner")
source=("https://pypi.io/packages/source/b/backports.os/backports.os-$pkgver.tar.gz")
sha256sums=('b472c4933094306ca08ec90b2a8cbb50c34f1fb2767775169a1c1650b7b74630')

prepare() {
  cd "${srcdir}"
  rm -rf ${builddir} | true
  cp -r "backports.os-${pkgver}" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  msg "Python 2 build for ${CARCH}"  
  cd "${srcdir}/python2-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python2 setup.py build
}

check() {
  msg "Python 2 tests for ${CARCH}"
  cd "${srcdir}/python2-build-${CARCH}"
# some tests fail
  ${MINGW_PREFIX}/bin/python2 setup.py pytest || true
}

package() {
  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

# We don't want the backports namespace in this package.
  rm "$pkgdir${MINGW_PREFIX}"/lib/python2.7/site-packages/backports/__init__.py*
}
